package com.cos66.store;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;

import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import com.cos66.handler.MagazineListHandler;
import com.cos66.model.MagazineItem;

public class MagazineListDataFromXml {
	
	private List<MagazineItem> data = null;
	public MagazineListDataFromXml(File file) {
//		FileUtils fileUtils = new FileUtils();
//		file = new File(fileUtils.getSDPATH() + "Cos66/list/Magazinelist.xml");
		try {
			SAXParserFactory factory = SAXParserFactory.newInstance();
			XMLReader reader = factory.newSAXParser().getXMLReader();
			MagazineListHandler handler = new MagazineListHandler();
			reader.setContentHandler(handler);
			reader.parse(new InputSource(new FileInputStream(file)));
			data = handler.getData();
		} catch (Exception e) {
			System.out.println(e.toString());
			e.printStackTrace();
		}
	}
	public List<MagazineItem> getData() {
		return data;
	}
}
